package zencstudio.sgrealtor.view.common;

import java.util.ArrayList;
import java.util.List;

import zencstudio.sgrealtor.view.phone.ChartActivity;
import zencstudio.sgrealtor.view.phone.ListCourseActivity;
import zencstudio.sgrealtor.view.phone.LoanCalculator;

import zencstudio.sgrealtor.R;

import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Button;
import android.widget.TableLayout;

public class ChartMenuBar extends TableLayout{

	private Button btnCalculate;
	private Button btnChart;
	private List<Button>lstButton = new ArrayList<Button>();
	public ChartMenuBar(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}
	public ChartMenuBar(Context context, AttributeSet attrs){
		super(context, attrs);
	}
	public void initUI(){
		btnCalculate = (Button) findViewById(R.id.btnCalculate);
		btnChart = (Button) findViewById(R.id.btnChart);
		lstButton.add(btnCalculate);
		lstButton.add(btnChart);
		btnCalculate.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(getContext(),LoanCalculator.class);
				intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
				getContext().startActivity(intent);
				
			}
		});
		btnChart.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(getContext(),ChartActivity.class);
				intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
				getContext().startActivity(intent);
				
			}
		});
		updateUI();
	}
	private void setButtonActive(Button b){
		for (Button btn : lstButton) {
			if(btn.equals(b))
				btn.setBackgroundResource(R.drawable.button_bg_selected);
			else
				btn.setBackgroundResource(R.drawable.button_bg);
		}
	}
	public void updateUI(){
		if(this.getContext() instanceof ChartActivity)
			setButtonActive(btnChart);
		if(this.getContext() instanceof LoanCalculator)
			setButtonActive(btnCalculate);
		//if(this.getContext() instanceof Grap)
			//setButtonActive(btnGraph);
	}
}
